iconv命令详解

您所在的位置:网站首页 iconv_open函数 core ONV_PATH iconv命令详解

iconv命令详解

2023-09-18 11:17| 来源: 网络整理| 查看: 265

 

基础命令学习目录首页  

 

原文链接:https://blog.csdn.net/u012313689/article/details/53033804

用途说明

iconv命令是用来转换文件的编码方式的(Convert encoding of given files from one encoding to another),比如它可以将UTF8编码的转换成GB18030的编码,反过来也行。JDK中也提供了类似的工具native2ascii。Linux下的iconv开发库包括iconv_open,iconv_close,iconv等C函数,可以用来在C/C++程序中很方便的转换字符编码,这在抓取网页的程序中很有用处,而iconv命令在调试此类程序时用得着。

常用参数

首先,我们要知道支持的字符编码有哪些,这个可以用-l参数得到(List known coded character sets)。

格式:iconv -l

其次,是怎样转换,如下所示:

格式:iconv -f from-encoding -t to-encoding inputfile

上面的调用方式,会把输出打印在屏幕上,如果要输出到文件,可以像下面这样

格式:iconv -f from-encoding -t to-encoding inputfile -o outputfile

使用示例 示例一 列出支持的字符编码

[root@new55 ~]# iconv -l  The following list contain all the coded character sets known.  This does not necessarily mean that all combinations of these names can be used for the FROM and TO command line parameters.  One coded character set can be listed with several different names (aliases).

  437, 500, 500V1, 850, 851, 852, 855, 856, 857, 860, 861, 862, 863, 864, 865,   866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3, 8859_4,   8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993, 10646-1:1993/UCS4,   ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4, ANSI_X3.110-1983, ANSI_X3.110,   ARABIC, ARABIC7, ARMSCII-8, ASCII, ASMO-708, ASMO_449, BALTIC, BIG-5,   BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS, BIGFIVE, BS_4730, CA, CN-BIG5, CN-GB,中间省略掉输出了。    EUCJP-OPEN, EUCJP-WIN, EUCJP, EUCKR, EUCTW, FI, FR, GB, GB2312, GB13000,   GB18030, GBK, GB_1988-80, GB_198880, GEORGIAN-ACADEMY, GEORGIAN-PS,   GOST_19768-74, GOST_19768, GOST_1976874, GREEK-CCITT, GREEK, GREEK7-OLD,   GREEK7, GREEK7OLD, GREEK8, GREEKCCITT, HEBREW, HP-ROMAN8, HPROMAN8, HU,中间省略掉输出了。    TIS620.2529-1, TIS620.2533-0, TIS620, TS-5881, TSCII, UCS-2, UCS-2BE,   UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UHC, UJIS, UK, UNICODE,   UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16, UTF-16BE,   UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16, UTF16BE, UTF16LE,   UTF32, UTF32BE, UTF32LE, VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM,   WINDOWS-31J, WINDOWS-874, WINDOWS-936, WINDOWS-1250, WINDOWS-1251,   WINDOWS-1252, WINDOWS-1253, WINDOWS-1254, WINDOWS-1255, WINDOWS-1256,   WINDOWS-1257, WINDOWS-1258, WINSAMI2, WS2, YU

太多了,我只想知道支持哪些中文格式的。  [root@new55 ~]# iconv -l | grep GB  CN-GB// CSGB2312// CSISO58GB1988// EBCDIC-CP-GB// GB// GB2312// GB13000// GB18030// GBK// GB_1988-80// GB_198880// ISO646-GB//

有没有发现奇怪的地方,每行显示一个,并且后面加了两个斜杠。  [root@new55 ~]#

示例二 将Google香港的Big5编码转换成GBK编码

[root@new55 ~]# curl -s http://www.google.com.hk/ | iconv -f big5 -t gbk  Googlewindow.google={kEI:"tFXZTNHKDcGTkAXpvOHhCA",kEXPI:"26637,27404",kCSI:{e:"26637,27404",ei:"tFXZTNHKDcGTkAXpvOHhCA",expi:"26637,27404"},ml:function(){},kHL:"zh-TW",time:function(){return(new Date).getTime()},log:function(b,d,c){var a=new Image,e=google,g=e.lc,f=e.li;a.onerror=(a.onload=(a.onabort=function(){delete g[f]}));g[f]=a;c=c||"/gen_204?atyp=i&ct="+b+"&cad="+d+"&zx="+google.time();a.src=c;e.li=f+1},lc:[],li:0,Toolbelt:{}}; id=ghead>所有網頁 圖片 影片 地圖 | 00000070  0d 0a 3c 68 74 6d 6c 20  78 6d 6c 6e 73 3d 22 68  |..



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3